package com.cc.common.config;

import com.google.common.base.Predicates;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    //请求参数为json、xml、key-value
    //响应参数为json、xml、key-value
    @Bean
    public Docket webApiConfig(Environment environment){
        // 设置要显示的swagger环境
        // Profiles profiles = Profiles.of("dev");
        // 判断是否处在自己设定的环境
        // boolean b = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                //.enable(b)
                .select()
                //.paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();

    }

    private ApiInfo webApiInfo(){
        return new ApiInfoBuilder()
                .title("晨创API文档")
                .description("本文档描述了晨创微服务接口定义")
                .version("v1.0")
                .contact(new Contact("xiaowu yuliang", "#", "55317332@qq.com"))
                .build();
    }
}
